package com.mantou.cdl.task;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import com.gargoylesoftware.htmlunit.CookieManager;
import com.mantou.cdl.proxy.ProxyAddress;


/**
 * @author dwjmantou
 * support:www.mantoub.com
 * @date 2015年5月4日
 * @version 1.0
 */
public class User {

	private static AtomicInteger userNumber = new AtomicInteger(0);
	private AtomicInteger taskNumber = new AtomicInteger(0);
	private static User defaultUser;
	private String userName;
	private String password;
	private int userID;
	private CookieManager cookieSpace;
	private boolean cookieEnable = false;
	private boolean javaScriptEnable = false;
	private List<ProxyAddress> proxspace = null;
	
	
	public List<ProxyAddress> getProxspace() {
		return proxspace;
	}

	public void setProxspace(List<ProxyAddress> proxspace) {
		this.proxspace = proxspace;
	}

	public User(String userName, String password) {
		this.userName = userName;
		this.password = password;
		userID = userNumber.addAndGet(1);
	}

	public static synchronized User getdefaultUser(String userName,String password){
		if(defaultUser == null){
			defaultUser = new User(userName, password);
			defaultUser.cookieSpace = new CookieManager();
		}
		return defaultUser;
	}
	
	public void setCookieEnable(boolean cookieEnable){
		if(cookieEnable && cookieSpace == null){
			cookieSpace = new CookieManager();
		}
		
		this.cookieEnable = cookieEnable;
	}

	public int getUserID() {
		return userID;
	}

	public void setUserID(int userID) {
		this.userID = userID;
	}

	public boolean isJavaScriptEnable() {
		return javaScriptEnable;
	}

	public void setJavaScriptEnable(boolean javaScriptEnable) {
		this.javaScriptEnable = javaScriptEnable;
	}

	public boolean isCookieEnable() {
		return cookieEnable;
	}
	
	
}
